﻿using B.S.Filtration.ErrorCode;
using B.S.Filtration.Write.Api.Application.Command.DOMDetails;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Filtration.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DOMDetailsController : ControllerBase
    {

        private readonly IMediator mediator;

        public DOMDetailsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加DOM配件
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddDOMDetails(AddDOMDetailsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改BOM配件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateDOMDetails(UpdateDOMDetailsCommand request) {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除BOM配件信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DeleteDOMDetails(DeleteDOMDetailsCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
